import {GetAllDocter,AddDocter,DeleteDocter,UpdateDocter,GetAllFriend,AddFriend,UpdateFriend,DeleteFriend,getAllCommentary,DeleteCommentary} from '@/api/doctorWithFriend'
const state = {
    doctordata:[],
    friendData:[],
    CommentData:[],//评论数据
}
const actions = {
    //拿到所有医生数据
    async GetAllDocterinfo(context,data){
        let res = await GetAllDocter(data)
        if(res.data.code === 0){
            context.commit('GETALLDOCTOR',res.data.result.list)
            return 'ok'
        }
    },
    //新增医生
    async AddDocterInfo(context,data){
        let res = await AddDocter(data)
        if(res.data.code == 0){
             return 'ok'
        }
       
    },
    //删除医生
    async DeleteOneDocter(context,id){
        let res = await DeleteDocter(id)
        if(res.data.code == 0){
            return 'ok'
        }    
    },
    //修改医师
    async updateDocter(context,data){
        let res = await UpdateDocter(data)
        if(res.data.code === 0){
            console.log(res)
            return 'ok'
        }
    },
    //得到所有朋辈数据
    async GetAllFriendInfo(context,data){
        let res = await GetAllFriend()
        if(res.data.code == 0){
            context.commit('GETFRIENDDATA',res.data.result)
            return 'ok'
        }
    },
    //新增朋辈
    async AddFriendInfo(context,data){
        let res = await AddFriend(data)
        if(res.data.code == 0){
            return 'ok'
        }
    },
    //修改朋辈
    async UpdateFriendInfo(context,data){
        let res = await UpdateFriend(data);
        if(res.data.code == 0){
            return 'ok'
        }
        
    },
    //删除朋辈
    async DeleteFriendInfo(context,id){
        let res = await DeleteFriend(id)
        if(res.data.code == 0){
            return 'ok'
        }
    },
    //拿到所有评论
    async GetAllCommentary(context,data){
        console.log(data)
        let res = await getAllCommentary({...data})
        console.log(res)
        if(res.data.code == 0){
            context.commit("GETCOMMDATA",res.data.result.list)
            return 'ok'
        }
    },
    //删除评论
    async deleteCommentary(context,id){
        let res = await DeleteCommentary(id)
         console.log(id)
        if(res.data.code == 0){
            return 'ok'
        }
    }

}
const mutations = {
    //得到医生数据
    GETALLDOCTOR(state,data){
        state.doctordata = data
    },
    //得到朋辈数据
    GETFRIENDDATA(state,data){
        state.friendData = data
    },
    GETCOMMDATA(state,data){
        state.CommentData = data
    }
}
const getters = {}
export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}